package com.atguigu.tingshu.order.api;

import com.atguigu.tingshu.common.annotation.login.LoginRequired;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.order.service.OrderInfoService;
import com.atguigu.tingshu.vo.order.OrderInfoVo;
import com.atguigu.tingshu.vo.order.TradeVo;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 订单管理
 * @author sun
 */
@RestController
@RequestMapping("api/order/orderInfo")
public class OrderInfoApiController {

	@Resource
	private OrderInfoService orderInfoService;


	/**
	 * 订单确认页
	 * @param tradeVo 订单确认对象
	 * @return 订单Vo 对象
	 */
	@LoginRequired
	@PostMapping("trade")
	public Result<OrderInfoVo> trade(@RequestBody@Validated TradeVo tradeVo){
		return Result.ok(orderInfoService.trade(tradeVo));
	}

	/**
	 * 提交订单
	 * @param orderInfoVo 订单对象
	 * @return 订单id
	 */
	@PostMapping("submitOrder")
	@LoginRequired
	public Result<Map<String,Object>> submitOrder(@RequestBody OrderInfoVo orderInfoVo){
		return Result.ok(orderInfoService.submitOrder(orderInfoVo));
	}

}

